<?php


namespace app\app\controller\sys;


use app\model\DeptModel;
use app\services\Permission;

class Dept
{
    /**
     * @Permission(action="sys:dept:lst")
     */
    public function lst(){
        $deptModel = new DeptModel();
        $where=[['deleted','=',0]];
        $dlst = $deptModel->where($where)->select();
        return success($dlst);
    }

    /**
     * @Permission(action="sys:dept:add")
     */
    public function add(){
        $deptModel = new DeptModel();
        $_dept = json_decode(input('dept'), true);
        $_dept['add_time']=time();
        $res = $deptModel::create($_dept);
        return $res ? success(null,0,"添加成功") : error(1,"添加失败");
    }

    /**
     * @Permission(action="sys:dept:edt")
     */
    public function edt(){
        $deptModel = new DeptModel();
        $_dept = json_decode(input('dept'), true);
        $_dept['edit_time']=time();
        $res = $deptModel::update($_dept);
        return $res ? success(null,0,"修改成功") : error(1,"修改失败");
    }

    /**
     * @Permission(action="sys:dept:del")
     */
    public function del(){
        $deptModel = new DeptModel();
        $_dept_id = input("dept_id");
        $where[]=['dept_id','in',strval($_dept_id)];
        $res = $deptModel->where($where)->update(["deleted"=>1]);
        return $res ? success(null,0,"删除成功") : error(1,"删除失败");
    }

}